#熔断

#部署 httpbin 服务
kubectl apply -f route-test/httpbin.yaml

#创建一个目标规则，在调用 httpbin 服务时应用熔断设置
kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: httpbin
spec:
  host: httpbin
  trafficPolicy:
    connectionPool:
      tcp:
        maxConnections: 1
      http:
        http1MaxPendingRequests: 1
        maxRequestsPerConnection: 1
    outlierDetection:
      consecutiveErrors: 1
      interval: 1s
      baseEjectionTime: 3m
      maxEjectionPercent: 100
EOF

#向客户端注入 Istio Sidecar 代理，以便 Istio 对其网络交互进行管理
kubectl apply -f <(istioctl kube-inject -f route-test/fortio-deploy.yaml)

#登入客户端 Pod 并使用 Fortio 工具调用 httpbin 服务
FORTIO_POD=$(kubectl get pod | grep fortio | awk '{ print $1 }')
kubectl exec -it $FORTIO_POD  -c fortio /usr/bin/fortio -- load -curl  http://httpbin:8000/get

#发送并发数为 2 的连接（-c 2），请求 20 次（-n 20）
kubectl exec -it $FORTIO_POD  -c fortio /usr/bin/fortio -- load -c 2 -qps 0 -n 20 -loglevel Warning http://httpbin:8000/get

#并发3
kubectl exec -it $FORTIO_POD  -c fortio /usr/bin/fortio -- load -c 3 -qps 0 -n 30 -loglevel Warning http://httpbin:8000/get


#查看熔断详情

kubectl exec $FORTIO_POD -c istio-proxy -- pilot-agent request GET stats | grep httpbin | grep pending